From cf77461578022021f33c89502484d936db438500 Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Fri, 13 Feb 2004 10:14:12 +0000 Subject: [PATCH] bitkeeper revision 1.724 (402ca374dzl4iEPzK71tvTWpDEYxgw) XenoUtil.py, xc_dom_control.py, VBD-HOWTO.txt: Merge toolset changes from v1.2. --- docs/VBD-HOWTO.txt | 22 +++++++++++++++++++++- tools/examples/xc_dom_control.py | 4 ++++ tools/xc/py/XenoUtil.py | 22 ++++++++++++++-------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/docs/VBD-HOWTO.txt b/docs/VBD-HOWTO.txt index b1d12a5f96..870ea2e040 100644 --- a/docs/VBD-HOWTO.txt +++ b/docs/VBD-HOWTO.txt @@ -204,6 +204,26 @@ just before deallocation (automated support for this may be added at a later date). +Side note: The xvd* devices +--------------------------- + +The examples in this document make frequent use of the xvd* device nodes for +representing virtual block devices. It is not a requirement to use these with +Xen, since VBDs can be mapped to any IDE or SCSI device node in the system. +Changing the the references to xvd* nodes in the examples below to refer to +some unused hd* or sd* node would also be valid. + +They can be useful when accessing VBDs from dom0, since binding VBDs to xvd* +devices under will avoid clashes with real IDE or SCSI drives. + +There is a shell script provided in tools/misc/xen-mkdevnodes to create these +nodes. Specify on the command line the directory that the nodes should be +placed under (e.g. /dev): + +> cd {root of Xen source tree}/tools/misc/ +> ./xen-mkdevnodes /dev + + Dynamically Registering VBDs ---------------------------- @@ -306,7 +326,7 @@ vbd_list variable, for instance using the line: (Note that you need to use quotes here, since config files are really small Python scripts.) -To specify the mapping on the commandline, you'd use the -d switch and supply +To specify the mapping on the command line, you'd use the -d switch and supply the triple as the argument, e.g.: > xc_dom_create.py [other arguments] -d phy:hdc,/dev/whatever,r diff --git a/tools/examples/xc_dom_control.py b/tools/examples/xc_dom_control.py index 59d137837e..638a509106 100755 --- a/tools/examples/xc_dom_control.py +++ b/tools/examples/xc_dom_control.py @@ -229,6 +229,10 @@ elif cmd == 'vbd_add': segments = XenoUtil.lookup_disk_uname(uname) + if not segments: + print "Lookup Failed" + sys.exit(1) + if XenoUtil.vd_extents_validate(segments,writeable) < 0: print "That mapping is too unsafe for the current VBD expertise level" sys.exit(1) diff --git a/tools/xc/py/XenoUtil.py b/tools/xc/py/XenoUtil.py index 68f4f02f54..e3b49bd99a 100644 --- a/tools/xc/py/XenoUtil.py +++ b/tools/xc/py/XenoUtil.py @@ -314,7 +314,7 @@ def vd_create(size_mb, expiry): FROM vdisks NATURAL JOIN vdisk_extents NATURAL JOIN vdisk_part WHERE expires AND expiry_time <= datetime('now') - ORDER BY expiry_time asc, vdisk_extent_no desc + ORDER BY expiry_time ASC, vdisk_extent_no DESC """) # aims to reuse the last extents # from the longest-expired disks first @@ -389,7 +389,7 @@ def vd_lookup(id): if not count: cx.close() - return -1 + return None cu.execute("SELECT size from vdisks WHERE vdisk_id = " + id) real_size, = cu.fetchone() @@ -410,6 +410,7 @@ def vd_lookup(id): NATURAL JOIN vdisk_part WHERE vdisk_extents.vdisk_id = """ + id + + " ORDER BY vdisk_extents.vdisk_extent_no ASC" ) extent_tuples = cu.fetchall() @@ -509,7 +510,7 @@ def vd_enlarge(vdisk_id, extra_size_mb): FROM vdisks NATURAL JOIN vdisk_extents NATURAL JOIN vdisk_part WHERE expires AND expiry_time <= datetime('now') - ORDER BY expiry_time asc, vdisk_extent_no desc + ORDER BY expiry_time ASC, vdisk_extent_no DESC """) # aims to reuse the last extents # from the longest-expired disks first @@ -779,7 +780,7 @@ def vd_cp_to_file(vdisk_id,filename): extents = vd_lookup(vdisk_id) - if extents < 0: + if not extents: return -1 file_idx = 0 # index into source file, in sectors @@ -827,9 +828,12 @@ def vd_read_from_file(filename,expiry): returns [string] : vdisk ID for the destination vdisk """ - size_sectors = os.stat(filename).st_size / 512 + size_bytes = os.stat(filename).st_size - vdisk_id = vd_create(size_sectors / ( 2 * 1024 ),expiry) + (size_mb,leftover) = divmod(size_bytes,1048580) # size in megabytes + if leftover > 0: size_mb += 1 # round up if not an exact number of MB + + vdisk_id = vd_create(size_mb, expiry) if vdisk_id < 0: return -1 @@ -840,10 +844,12 @@ def vd_read_from_file(filename,expiry): cu.execute("""SELECT partition, extent_size, part_extent_no FROM vdisk_part NATURAL JOIN vdisk_extents WHERE vdisk_id = """ + vdisk_id + """ - ORDER BY vdisk_extent_no""") + ORDER BY vdisk_extent_no ASC""") extents = cu.fetchall() + size_sectors = size_mb * 2048 # for feeding to dd + file_idx = 0 # index into source file, in sectors def write_extent_to_vd((partition, extent_size, part_extent_no), @@ -856,7 +862,7 @@ def vd_read_from_file(filename,expiry): + " count=" + str(min(extent_size, size_sectors - file_idx)) + " > /dev/null") - return file_idx + extent_size + return extent_size for i in extents: file_idx += write_extent_to_vd(i, file_idx, filename) -- 2.30.2